package com.aloda.utils;

import cn.hutool.core.util.RandomUtil;

import java.util.regex.Pattern;

public class TeamUtils {
    public static boolean checkTeamName(String teamName) {
        // 校验队伍名称
        Pattern teamNamePattern = Pattern.compile("^[\\u4e00-\\u9fa5a-zA-Z0-9]{2,8}$");
        return teamName != null
                && !teamName.isEmpty()
                && teamNamePattern.matcher(teamName).matches();
    }

    public static boolean checkPassword(String password) {
        // 校验密码
        Pattern passwordPattern = Pattern.compile("^(?=.*[a-zA-Z])(?=.*\\d)[a-zA-Z\\d]{4,16}$");
        return password != null
                && !password.isEmpty()
                && passwordPattern.matcher(password).matches();
    }

    public static boolean checkDescription(String desc) {
        // 校验队伍简介：字数0-100
        Pattern descPattern = Pattern.compile("^.{0,100}$");
        return desc != null && descPattern.matcher(desc).matches();
    }

    public static String getTeamNumber(String id) {
        String randomString = RandomUtil.randomString(4);
        Long timeMillis = System.currentTimeMillis();
        return timeMillis + randomString + id;
    }
}
